//
//  CustomPushAnimation.m
//  动画
//
//  Created by 张国文 on 16/9/13.
//  Copyright © 2016年 李国峰. All rights reserved.
//

#import "CustomPushAnimation.h"

@interface CustomPushAnimation ()

@end

@implementation CustomPushAnimation

- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
{
    return 1.0;
}

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    // 起始VC
    UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    //添加toView到上下文
    
    //  [[transitionContext containerView] insertSubview:toViewController.view belowSubview:fromViewController.view];
    [[transitionContext containerView] addSubview:fromViewController.view];
    [[transitionContext containerView] addSubview:toViewController.view];
    
    //自定义动画
    
    toViewController.view.transform = CGAffineTransformMakeTranslation(375, 667);
    
    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
        
        fromViewController.view.transform = CGAffineTransformMakeTranslation(-375, -667);
        
        toViewController.view.transform = CGAffineTransformIdentity;
        
    } completion:^(BOOL finished) {
        
        fromViewController.view.transform = CGAffineTransformIdentity;
        
        // 声明过渡结束时调用 completeTransition: 这个方法
        
        [transitionContext completeTransition:![transitionContext transitionWasCancelled]];
        
    }];
  
    
}

@end
